var express = require("express");
var router = express.Router();
// var async = require("async");
const comment = require("../model/comment");
const article = require("../model/article");
const answer = require("../model/answer");
const user_login = require("../model/user_login");

const resource = require("../model/resource");
// const like = require("../model/like")

router.post("/api/v1/getSituation", async (req, res) => {
  console.log(req.body);
  let userid = req.body.userid;

  let user = await user_login.find({ _id: userid }).exec();
  let articleNum = await article
    .find({
      userid: userid,
      audit: true
    })
    .count();

  let resourceNum = await resource
    .find({
      userid: userid,
      audit: true
    })
    .count();

  let commenteNum = await comment
    .find({
      userid: userid
    })
    .count();

  let answerNum = await answer
    .find({
      userid: userid
    })
    .count();
  res.json({
    code: 200,
    data: {
      articleNum: articleNum + resourceNum,
      commenteNum,
      answerNum,
      integral: user[0].integral
    }
  });
});

// 导出模块（在 app.js 中引入）
module.exports = router;
